<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2018/12/26
 * Time: 9:02
 */
namespace app\admin\controller;
use  think\Db;
class Yhorder extends Base {
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $map =array();
            if(isset($key)&&$key!="")
            {
                $map['uuu.user_username'] = ['like',"%" . $key . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['a.order_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['a.order_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['a.order_time'] = ['between time',[$start,$end]];
            }
            //支付方式
            if(isset($order_status) && $order_status != 0){
                $map['a.order_status'] = $order_status;
            }
            //订单状态
            if(isset($order_type) && $order_type != 0){
                $map['a.order_type'] = $order_type;
            }
//            $map['a.order_del'] = 1;
            $map['a.order_type_on'] = 1;
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_order')
                ->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.order_userid','left')
                ->where($map)
                ->count();//计算总页面
            $list = Db::table('up_order')
                ->alias ('a')
                ->join('up_u_user uuu','uuu.user_id = a.order_userid','left')
                ->page($page, $limit)
                ->where($map)
                ->field('a.*,uuu.user_username')
                ->order('a.order_id desc')
                ->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        if(session('?order_id_y')){
            session('order_id_y',null);
        }
        return $this->fetch();
    }


    public function detail(){

        if(request()->isAjax()){
            extract(input());

            $map =array();
            if(isset($key)&&$key!="")
            {
                $map['oi_good_name'] = ['like',"%" . $key . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['a.oi_pay_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['a.oi_pay_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['a.oi_pay_time'] = ['between time',[$start,$end]];
            }
            $map['a.oi_order_id'] =input('param.id');
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_order_info')->alias('a')
                ->where($map)
                ->count();//计算总页面
            $list = Db::table('up_order_info')
                ->alias ('a')
                ->page($page, $limit)
                ->where($map)
                ->field(
                    ['a.oi_id','a.oi_price',
                        'oi_good_thumb',
                        'a.oi_num','a.oi_pay_time','a.oi_good_name'
                    ])
                ->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        if(!session('?order_id_y')){
            session('order_id_y',input('param.id'));
        }
        return $this->fetch();
    }
}